﻿using System;

namespace DBMock.Builders
{
    /// <summary>
    /// 字符串日期builder
    /// </summary>
    public class StrDateBuilder : Builder
    {
        DateBuilder dateBuilder; //日期builder
        string format; //日期格式

        /// <summary>
        /// 初始化StrDateBuilder
        /// </summary>
        /// <param name="seed">随机数种子</param>
        /// <param name="minDate">最小日期</param>
        /// <param name="maxDate">最大日期</param>
        /// <param name="format">日期格式</param>
        public StrDateBuilder(int seed, DateTime minDate, DateTime maxDate, string format)
            : base(seed)
        {
            dateBuilder = new DateBuilder(seed, minDate, maxDate);
            this.format = format;
        }

        public override object Build()
        {
            var date = (DateTime)(dateBuilder.Build());

            return string.IsNullOrEmpty(format) ?
                date.ToShortDateString() :
                date.ToString(format);
        }
    }
}
